/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.github.ngocnh210.TrueName.Util;

import com.github.ngocnh210.TrueName.TrueName;
import java.io.File;
import java.util.logging.Logger;
import org.bukkit.util.config.Configuration;

/**
 *
 * @author NgocNH
 */
public class Config {
    public static TrueName plugin;
    public static Logger log = Logger.getLogger("Minecraft");

    public static String extension = ".yml";
    public static boolean loaded = false;

    //Main Config
    public static boolean has_badcharacters;
    public static boolean autoupdate = false;
    public static String version;
    public static String username_minimum_length;
    public static String username_maximum_length;

    //Language
    public static String message_username_minimum, message_username_maximum;

    public static String filter_username, filter_action, filter_check;

    public static String command_reload;

    public static String system_writting_default_config, system_found_extension, system_load_config,
                  system_loaded, system_saved, system_version, system_enabled, system_disabled;

    public static Configuration template = null;

    public Config(String config, String directory, String filename) {
        template = new Configuration(new File(directory, filename));
        template.load();
        if (config.equalsIgnoreCase("config")) {
            log.info("[" + plugin.pluginName + "] Dang tai thiet lap cau hinh.");
            version = getString("version", plugin.pluginVersion);
            autoupdate = getBoolean("autoupdate", false);
            username_minimum_length = getString("username.minimum", "3");
            username_maximum_length = getString("username.maximum", "16");
            filter_action = getString("filter.action", "kick");
            filter_check = getString("filter.check", "\"`~!@#$%^&*()-=+{[]}|\\:;\"<,>.?/ \"");
        } else if (config.equalsIgnoreCase("language")) {
            message_username_minimum = getString("message.username.minimum", "Ten Tai Khoan phai lon hon {USERMIN} ky tu!");
            message_username_maximum = getString("message.username.maximum", "Ten Tai Khoan phai nho hon {USERMAX} ky tu!");
            filter_username = getString("message.filter.username", "Ban bi Kick vi Tai Khoan co chua ky tu khong hop le: {USERBADCHARACTERS}!");
            command_reload = getString("commands.reload", "Lam moi cau hinh TrueName hoan tat!");
            system_writting_default_config = getString("system.writting_default_config", "Su dung cau minh mac dinh!");
            system_found_extension = getString("system.found_extension", "Tim thay .usetxt, thay doi duoi mo rong thanh .txt");
            system_load_config = getString("system.load_config", "Dang doc cau hinh.....");
            system_loaded = getString("system.loaded", "Doc cau hinh hoan tat!");
            system_saved = getString("system.saved", "Luu cau hinh hoan tat!");
            system_version = getString("system.version", "Phien Ban");
            system_enabled = getString("system.enabled", "Da Bat");
            system_disabled = getString("system.disabled", "Da Tat");
        }
        template.save();
    }

    public void save(String key, String line) {
        template.setProperty(key, line);
    }

    public static boolean getBoolean(String key, boolean value) {
        return template.getBoolean(key, value);
    }

    public static String getString(String key, String value) {
        return template.getString(key, value);
    }
}
